package com.zx.rabbitmq.springboot.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitMq 配置类
 *
 * @author Zx
 * @date 2021/5/31 17:54
 */
@Configuration
public class DirectRabbitMqConfiguration {
    /**
     * 1 声明交换机(广播模式)
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct_order_exchange", true, false);
    }

    /**
     * 2 声明队列
     *
     * @return
     */
    @Bean
    public Queue directSmsQueue() {
        return new Queue("sms.direct.queue", true);
    }

    @Bean
    public Queue directEmailQueue() {
        return new Queue("email.direct.queue", true);
    }


    /**
     * 3 完成关系绑定, 队列交换机绑定
     *
     * @return
     */
    @Bean
    public Binding directSmsBinding() {
        return BindingBuilder.bind(directSmsQueue()).to(directExchange()).with("sms");
    }

    @Bean
    public Binding directEmailBinding() {
        return BindingBuilder.bind(directEmailQueue()).to(directExchange()).with("email");
    }

}
